import { CHOOSE_MAP, MAP_BEFORE_INFO, REMOVE_MAP, CLEAR_MAP_LONGITUDE_LATITUDE } from 'Constants/chooseMap';
import * as routeActions from 'react-router-redux';

export function chooseMap(mapInfo) {
  return {
    type: CHOOSE_MAP,
    mapInfo
  };
}
export function mapBeforeInfo(mapInfo) {
  return {
    type: MAP_BEFORE_INFO,
    mapInfo
  };
}
export function removeMap() {
  return {
    type: REMOVE_MAP,
  };
}
export function clearMapLonLat() {
  return {
    type: CLEAR_MAP_LONGITUDE_LATITUDE,
  };
}
export function ChooseMapInfo(info) {
  return (dispatch) => {
    const mapInfo = {
      chooseMapLongitude: info.lnglat.getLng(),
      chooseMapLatitude: info.lnglat.getLat(),
    };
    dispatch(chooseMap(mapInfo));
    dispatch(routeActions.goBack());
  };
}

export function MapBeforeInfoStorage(info) {
  return (dispatch) => {
    const mapInfo = {
      mapBeforeInfo: info,
    };
    dispatch(mapBeforeInfo(mapInfo));
    dispatch(routeActions.push('/system/dispatch/support/special_manage/choose_map'));
  };
}

export function RemoveMapInfo() {
  return (dispatch) => {
    dispatch(removeMap());
  };
}

export function clearMapLongitudeLatitude() {
  return (dispatch) => {
    dispatch(clearMapLonLat());
  };
}
